<template>
	<view>
		<uni-nav-bar class="nav" status-bar background-color="" :border="false" left-icon="back" title="领券中心"
			@clickLeft="goback"></uni-nav-bar>
		<view class="adstop">
			<view class="bcg">
				<image class="img1" src="/static/ljuan4.png" mode=""></image>
				<image class="img2" src="../static/ljuan3.png" mode=""></image>
			</view>
			<view class="block_1">
				<image src="../static/ljuan2.png" mode=""></image>
				<view class="">
					平台通用券限量抢
				</view>
			</view>
		</view>
		<view class="block_2">
			<view class="coupon" :style="{background:
			 !item.take&&item.count == item.countTake?'#D9D9D9':''}" v-for="(item,index) in list" :key="index">
				<view class="coupon-info coupon-hole" :style="{color:
				!item.take&&item.count == item.countTake?'#969696':''}">
					<view class="">
						<view class="t1">
							<span v-if="item.couponType == '盲盒'">
								<span v-if="item.take">
									{{item.couponList[0].amount.integer}}</span>
								<span v-else>?</span>
							</span>
							<span v-else>
								{{item.couponList[0].amount.integer}}
								<text
									v-if="item.couponList[0].amount.decimal">.{{item.couponList[0].amount.decimal}}</text>
							</span>
						</view>
						<view class="t2">
							<span v-if="item.couponType == '盲盒'">
								<span v-if="item.take">满 {{item.couponList[0].amountRequire}} 可用</span>
								<span v-else>满 ??? 可用</span>
							</span>
							<span v-else>满 {{item.couponList[0].amountRequire}} 可用</span>
						</view>
					</view>
					<view class="r">
						<view class="" v-if="item.couponType == '盲盒'&&!item.take&&item.count == item.countTake">
							<view class="">
								全平台通用
							</view>
							<view class="t1" style="margin-right: 0rpx;">
								抢光啦~下次记得早点来哦~
							</view>
						</view>
						<view class="" v-else>
							<view class="" style="margin-right: 40rpx;">
								全平台通用
							</view>
							<view class="t1">
								截止至 {{item.timeEnd.substring(0,10)}}
							</view>
						</view>
					</view>
				</view>
				<view class="coupon-get">
					<view class="btn1" v-if="item.take" @click="goindex">去使用</view>
					<view class="" v-else>
						<image v-if='
						!item.take&&item.count == item.countTake' src="../static/ljuan1.png" mode=""></image>
						<view v-else class="btn2" @click="open(item)">立即领券</view>
					</view>
				</view>
			</view>
		</view>
		<view class="" style="height: 100rpx;">
			
		</view>
		<uni-popup ref="popup" type="center">
			<view class="popup">
				<view class="imgbcg">
					<image class="img" src="../static/ljuan5.png" mode=""></image>
					<view class="abs">
						<image src="../static/ljuan6.png" mode=""></image>
						<view class="t1">
							{{info.amount.integer}}
							<text v-if="info.amount.decimal">.{{info.amount.decimal}}</text>
						</view>
						<view class="t2">
							满 {{info.amountRequire}} 可用
						</view>
						<view class="ts">
							<view class="we">
								优惠多多~快去使用吧~
							</view>
							<view class="t"></view>
						</view>
						<view class="btn" @click="pageconsumer">
							立即查看
						</view>
					</view>
				</view>
				<view class="close" @click="close">
					<uni-icons size="40" color="#fff" type="close"></uni-icons>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		couponList,
		couponTake
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				list: [],
				info: {},
			};
		},
		onShow() {
			couponList({}).then(res => {
				this.list = res.data
				this.list.forEach(item => {
					item.couponList.forEach(price => {
						price.amount = this.$splitNumber(price.amount);
					})
				})
				console.log(this.list);
			})
		},
		methods: {
			goindex() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			goback() {
				uni.navigateBack()
			},
			pageconsumer() {
				this.$refs.popup.close()
				uni.navigateTo({
					url: '/mypage/consumer'
				})
			},
			close() {
				this.$refs.popup.close()
			},
			open(item) {
				console.log(item);
				couponTake({
					id: item.id
				}).then(res => {
					this.info = res.data
					this.info.amount = this.$splitNumber(this.info.amount)
					this.$refs.popup.open()
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #FBFBFB;
	}
	.adstop{
		width: 100%;
		position: sticky;
		top: 0%;
		z-index: 9;
		background: #FBFBFB;
	}

	.nav {
		position: fixed;
		top: 0%;
		z-index: 99;
		width: 100%;
	}

	.bcg {
		width: 100%;
		height: 316rpx;
		position: relative;
		.img1 {
			width: 100%;
			height: 316rpx;
			position: absolute;
		}
		.img2 {
			width: 312rpx;
			height: 52rpx;
			position: absolute;
			top: 225rpx;
			z-index: 1;
			left: 50%;
			transform: translateX(-50%);
		}
	}

	.block_1 {
		display: flex;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 36rpx;
		color: #000000;
		align-items: center;
		text-align: center;
		margin-left: 40rpx;

		image {
			width: 136rpx;
			height: 136rpx;
			margin-right: 24rpx;
		}
	}

	.block_2 {}

	.coupon {
		display: inline-flex;
		color: white;
		position: relative;
		overflow: hidden;
		background: linear-gradient(160deg, #B0F8F1 0%, #DDF6DD 42%, #BCEFD1 73%, #B0F8F1 100%);
		width: 710rpx;
		height: 158rpx;
		left: 20rpx;
		margin-bottom: 20rpx;
		border-radius: 12rpx;
	}

	.coupon-info {
		padding: 0rpx 34rpx;
		position: relative;
		min-width: 468rpx;
		border-right: 1px dashed #86929F;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		text-align: center;
		color: #000000;
		justify-content: space-between;

		.t1 {
			font-family: 'DINB';
			font-weight: bold;
			font-size: 72rpx;

			text {
				font-size: 40rpx;
			}
		}

		.t2 {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
		}

		.r {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 32rpx;
			text-align: center;

			.t1 {
				margin-right: 40rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 20rpx;
				margin-top: 8rpx;
			}
		}
	}

	.coupon-info::before {
		top: -0.5rem;
	}

	.coupon-info::after {
		bottom: -0.5rem;
	}

	// /* 使用两个边框为圆角的白色div制造半圆缺角，有个缺点是这个缺角必须与背景色相同（clip-path不好弄） */
	.coupon-hole::before,
	.coupon-hole::after {
		content: '';
		width: 1rem;
		height: 1rem;
		background-color: white;
		border-radius: 50%;
		position: absolute;
		right: -0.5rem;
	}

	.coupon-get {
		box-sizing: border-box;
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;

		image {
			width: 136rpx;
			height: 112rpx;
			position: absolute;
			bottom: 0%;
			right: 0%;
		}

		.btn1 {
			font-weight: bold;
			font-size: 30rpx;
			color: #000;
			width: 168rpx;
			height: 76rpx;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			border: 2rpx solid #000;
			text-align: center;
			line-height: 76rpx;
		}

		.btn2 {
			width: 168rpx;
			height: 76rpx;
			background: #000000;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			font-weight: bold;
			font-size: 30rpx;
			color: #fff;
			text-align: center;
			line-height: 76rpx;
		}

	}

	.popup {
		.close {
			margin-top: 6rpx;
			text-align: center;
		}

		.imgbcg {
			width: 630rpx;
			height: 560rpx;
			position: relative;

			.img {
				width: 630rpx;
				height: 560rpx;
			}

			.abs {
				position: absolute;
				width: 630rpx;
				height: 560rpx;
				top: 0%;
				padding: 84rpx 94rpx 54rpx 94rpx;
				box-sizing: border-box;
				text-align: center;

				image {
					width: 284rpx;
					height: 84rpx;
					margin-left: 40rpx;
				}

				.t1 {
					font-family: 'DINB';
					font-weight: bold;
					font-size: 72rpx;
					line-height: 70rpx;

					text {
						font-size: 40rpx;
					}
				}

				.t2 {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #000000;
					margin-top: 6rpx;
				}

				.ts {
					width: 380rpx;
					height: 40rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #000000;
					margin: 10rpx auto;
					position: relative;

					.we {
						position: absolute;
						z-index: 9;
						font-size: 28rpx;
						left: 50rpx;
					}

					.t {
						width: 380rpx;
						height: 12rpx;
						background: #38CDA5;
						border-radius: 6rpx 6rpx 6rpx 6rpx;
						position: absolute;
						bottom: 0rpx;
					}
				}

				.btn {
					margin-top: 74rpx;
					width: 442rpx;
					height: 92rpx;
					background: #000000;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 32rpx;
					color: #FFFFFF;
					line-height: 92rpx;
				}

			}
		}
	}
</style>